
#ifndef _daqAdapter_h_
#define _daqAdapter_h_

#include<vector>
#include<string>

#include"NIDAQmx.h"

typedef enum{AI, AO, DI, DO, CTR, GROUP} TaskType;

// low-level NIDAQ access, task life management
// map (SlotId, chId) -> (uniqueId)
//provides spline calibration fitting
class DaqIO
{
protected:
	static const int inAverage = 10;				// number of input samples to average
	static const int inBufDur=5;					// duration of internal buffer (sec)
	static int taskCount;							// global task Id issuer
	
	TaskHandle task;
	TaskType taskType;
	bool readBlocking;
	double *buffer;

	//singleton pattern
	DaqIO():task(NULL),buffer(NULL){};
	DaqIO(const DaqIO&){};
	DaqIO& operator=(const DaqIO &){};
public:
	uInt32 numChan;									// # of channels
	DaqIO(const char* chSpec, const int rate, const double minVal, const double maxVal, const bool isReadBlocking=true);
	virtual int read(double* data);
	virtual int write(const double* data);
	~DaqIO();
};


class DaqGroupIO : public DaqIO //inheritance mainly for interfacing purpose
{
protected:
	//Task Handles
	std::vector<DaqIO*> daqGroup;					// nidaq task handles

	//Singleton
	DaqGroupIO(){};
	DaqGroupIO(const DaqGroupIO&){};
	DaqGroupIO& operator=(const DaqGroupIO&){};
public:
	DaqGroupIO(const std::vector<std::string> inChanGroup, const int rate, 
				const double minVal=0, const double maxVal=10);
	~DaqGroupIO();
	int write(const double *data);
	int read(double *data);
};


#endif
